<html>
<head><meta charset="utf-8"><title>OCI Image Target using Cargo · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html">OCI Image Target using Cargo</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226331746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226331746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226331746">(Feb 14 2021 at 23:26)</a>:</h4>
<p>There is a project cargo-wharf made by Denys Zariaiev that I used for a while before it fell out of maintenance.  It uses BuildKit as a sort of llvm and Cargo as the language to produce CRI (Container Runtime Interface) containers. The sort of containers you run with Docker or Kubernetes. Check it out:</p>
<p><a href="https://github.com/denzp/cargo-wharf">https://github.com/denzp/cargo-wharf</a></p>
<p>I feel given the prevalence on container based development today it would be very useful to have as a first class supported target like x86_64-unknown-linux-cri. Being able to generate an optimized container directly would really set Rust apart. </p>
<p>Just wanted to throw this thought out there. Thanks! :)</p>



<a name="226540871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226540871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226540871">(Feb 16 2021 at 16:53)</a>:</h4>
<p>I suppose since Rust uses llvm it would make sense to start there and make a CRI backend. Then work on enabling it rustc. If being rather opinionated with the output there may not be a need for any frontend work in cargo initially. But I am sure eventually some options would be wanted.</p>



<a name="226543539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226543539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226543539">(Feb 16 2021 at 17:09)</a>:</h4>
<p>I suppose I could use cgo to wrap buildkit to call from the C++ llvm backend code... It really should end up being an extra step on existing targets. Probably a way to reuse them.</p>



<a name="226546854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226546854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226546854">(Feb 16 2021 at 17:31)</a>:</h4>
<p>Why would rustc need a CRI backend? It isn't a compilation target, but a combination of an API and some libraries. This has nothing to do with compilation itself. It can be implemented as a regular crate.</p>



<a name="226681556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226681556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226681556">(Feb 17 2021 at 16:15)</a>:</h4>
<p>That's true. rustc doesn't need a CRI backend and, it can be implement as a regular crate.  Although, the cargo-wharf project takes another route. </p>
<p>Motivationally. having an easy CRI path when developing for platforms that only expose container runtimes would be very convenient. There seems to be a better way to go about doing this then having tens of thousands of man hours spent optimizing dockerfiles. So  I am thinking about it. </p>
<p>Building a container nowadays is pretty much limit to wrapping a pre-generated binary. So all work happens post-compilation. However, that's a design choice. One that makes container building very portable. And I do think you can take very far. I imagine there are benefits to be had doing the building up the chain. But I am not good enough to say what those would be.</p>
<p>The cargo and rustc do take user inputs in the cargo file, as arguments, and as env variable that can be used to construct an optimal container image with almost no additional input from the user. </p>
<p>For example, in the simplest case everything is statically linked.  However if the binary has dynamic links to  a library then we know we need to pull this library into the container as a layer. And in the compilation chain we have the information to do this automatically (maybe with some user specification of library location/version). Yet, people spend alot of time on this problem set. Even the simpler case of a statically linked binary. You can see first hand with a quick browse.</p>
<p>Obviously, we are aware of where the binaries are, there name,  versions, arch, and os which we can resuse in the container spec.  Overall I don't see anything in the OCI spec that can be supplied by preexisting user inputs.</p>
<p>You could even go further into the runtime specifications,  such as storage types and permission. If we see from the code that there are only read calls to the filesystem we can set minimal read-only permissions. But this is off-topic.</p>
<p>Perhaps building on cargo wharf with a crate that implements a cargo extension while pulling in the builder image functionality as a native  function would be a good route.</p>



<a name="226682704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226682704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226682704">(Feb 17 2021 at 16:22)</a>:</h4>
<p>It would be nice to push parts of the functionality lower in stack if only so that other language can reuse the work.</p>



<a name="226687140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226687140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226687140">(Feb 17 2021 at 16:49)</a>:</h4>
<p>Also I suppose I should be referring to OCI instead CRI here if are going to ignore runtime settings so I am gonna edit the title.</p>



<a name="226803353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226803353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226803353">(Feb 18 2021 at 12:36)</a>:</h4>
<div class="codehilite"><pre><span></span><code>                   OCI LLVM Crate---\                                               
                      ^              ------\                                        
                      |                     ---&gt;Rust BuildKit--------------&gt;Buildkit
                      |                    --/                                      
                   OCI Crago Plugin Crate-/                                         
                      ^                                                             
                      |                                                             
                      |                                                             
User-----------------&gt; Cargo---------------&gt;OCI Image
</code></pre></div>



<a name="226804607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226804607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226804607">(Feb 18 2021 at 12:48)</a>:</h4>
<p><a href="https://github.com/gary-ascuy/cargo-rocket-docker">https://github.com/gary-ascuy/cargo-rocket-docker</a><br>
<a href="https://github.com/denzp/cargo-wharf">https://github.com/denzp/cargo-wharf</a><br>
<a href="https://github.com/denzp/rust-buildkit">https://github.com/denzp/rust-buildkit</a></p>



<a name="226809353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/226809353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#226809353">(Feb 18 2021 at 13:31)</a>:</h4>
<p>In what form would LLVM have to be involved in this?</p>



<a name="227101964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/OCI%20Image%20Target%20using%20Cargo/near/227101964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mateus Amin <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/OCI.20Image.20Target.20using.20Cargo.html#227101964">(Feb 20 2021 at 16:25)</a>:</h4>
<p>It would be nice to grab and use inputs going into the llvm space so the library can be reused in other llvm frontends. I am going to ask for thoughts on the llvm forums. I imagine this may not be feasible depending on how frontends are integrating into the toolchain.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>